package com.mangabiz.market.entities;

// Start of user code for imports
import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;


// End of user code for imports

/**
 * Warning: no comment in the model for interface Product.
 */
@Entity
public class Product implements Serializable {


	/**
	 * serialVersionUID is used for serialization.
	 */
	private static final long serialVersionUID = 1L;


	/**
	 * Constant representing the name of the automatic primary key field.
	 */
	public static final String PROP_ID = "id";


	/**
	 * Constant representing the name of the field name.
	 */
	public static final String PROP_NAME = "name";


	/**
	 * Constant representing the name of the field category.
	 */
	public static final String PROP_CATEGORY = "category";


	/**
	 * Automatic primary key.
	 */
	protected Long id;


	/**
	 * Field name.
	 */
	protected String name;


	/**
	 * Field category.
	 */
	protected Category category;


	/**
	 * Default constructor.
	 */
	public Product() {
		super();
	}


	/**
	 * Returns the identifier.
	 * 
	 * @return Returns id.
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}


	/**
	 * Sets a value to parameter Id.
	 * 
	 * @param someId
	 *            Value of the identifier.
	 */
	public void setId(final Long someId) {
		id = someId;
	}


	/**
	 * Constructor with all parameters initialized.
	 * 
	 * @param someName
	 *            Warning, no comment in the model.
	 * @param someCategory
	 *            Warning, no comment in the model.
	 */
	public Product(String someName, Category someCategory) {
		name = someName;
		category = someCategory;
	}


	/**
	 * Returns name.
	 * 
	 * @return Warning, no comment in the model.
	 */
	@Basic(optional = false)
	@Column(nullable = false, length = 255)
	public String getName() {
		return name;
	}


	/**
	 * Sets a value to parameter name.
	 * 
	 * @param someName
	 *            Warning, no comment in the model.
	 */
	public void setName(final String someName) {
		name = someName;
	}


	/**
	 * Returns category.
	 * 
	 * @return Warning, no comment in the model.
	 */
	@ManyToOne
	public Category getCategory() {
		return category;
	}


	/**
	 * Sets a value to parameter category.
	 * 
	 * @param someCategory
	 *            Warning, no comment in the model.
	 */
	public void setCategory(final Category someCategory) {
		category = someCategory;
	}


	/**
	 * Equality test based on attributes values.
	 * 
	 * @param other
	 *            Value to compare
	 * @return Returns true if and only if given object is an instance of
	 *         Product and the given object has the same PK as this if the PK is
	 *         not null or their fields are equal.
	 */
	@Override
	public boolean equals(final Object other) {
		// Start of user code for equals
		if (this == other) {
			return true;
		}
		if (!(other instanceof Product)) {
			return false;
		}
		final Product castedOther = (Product) other;
		if (id != null && castedOther.getId() != null) {
			return id.equals(castedOther.getId());
		}
		if ((name == null && castedOther.getName() != null)
				|| (name != null && !name.equals(castedOther.getName()))) {
			return false;
		}
		if ((category == null && castedOther.getCategory() != null)
				|| (category != null && !category.equals(castedOther
						.getCategory()))) {
			return false;
		}
		return true;
		// End of user code for equals
	}


	/**
	 * HashTable code based on attributes hashcodes.
	 * 
	 * @return Returns hash value
	 */
	@Override
	public int hashCode() {
		// Start of user code for hashCode
		int result = 0;
		if (id != null) {
			result = id.hashCode();
		} else {
			if (name != null) {
				result = 29 * result + name.hashCode();
			}
		}
		return result;
		// End of user code for hashCode
	}

	// Start of user code for private methods
	// TODO Remove this line and add your private methods here
	// End of user code for private methods

}
